﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Remoting.Messaging;

namespace ServiceController
{
    public delegate DataAccess.DataAccessResult ChangeConfigurationFileDelegate(String SubscriptionID, String CertificatePath, String ServiceName, String DeploymentSlot, String ConfigFile);
    public partial class ServiceController
    {

        ChangeConfigurationFileDelegate _ChangeConfigurationFileDelegate;
        public void ChangeConfigurationFileAsync(String SubscriptionID, String CertificatePath, String ServiceName,String DeploymentSlot, String ConfigFile, object UserState)
        {
            _ChangeConfigurationFileDelegate.BeginInvoke(SubscriptionID, CertificatePath,ServiceName, DeploymentSlot, ConfigFile, new AsyncCallback(ChangeConfigurationFileCallback), UserState);
        }

        private void ChangeConfigurationFileCallback(IAsyncResult ar)
        {
            AsyncResult aresult = (AsyncResult)ar;
            DataAccess.DataAccessResult result = _ChangeConfigurationFileDelegate.EndInvoke(ar);
            OnChangeConfigFileComplete(new ServiceControllerEventArgs()
            {
                error = result.Error,
                UserState = ar.AsyncState,
                IsOperationSuccessful = result.IsOperationSuccessful,
            });
        }

        private DataAccess.DataAccessResult ChangeConfigurationFile(String SubscriptionID, String CertificatePath, String ServiceName, String DeploymentSlot, String ConfigFile)
        {
            DataAccess.DataAccessResult result = da.ChangeConfigFile(SubscriptionID, CertificatePath, ServiceName, DeploymentSlot, ConfigFile);
            return result;
        }
    }
}
